<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="代征主体">
              <a-input placeholder="请输入代征主体" v-model="queryParam.dzzt"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <a-input placeholder="请输入企业名称" v-model="queryParam.qymc"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属销售">
              <j-dict-select-tag placeholder="请选择所属销售" v-model="queryParam.ssxs" dictCode="bu_gsfwpt_xsgl,name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属省">
              <!--                <j-dict-select-tag placeholder="请选择所属省" v-model="queryParam.sss" dictCode="sj_code"/>-->
              <j-area-linkage type='cascader' v-model="queryParam.sss" placeholder="请选择所属省/市" ></j-area-linkage>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同是否归档">
              <j-dict-select-tag placeholder="请选择合同是否归档" v-model="queryParam.htsfgd" dictCode="ht_sfgd"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务类型">
              <j-dict-select-tag placeholder="请选择业务类型" v-model="queryParam.wslx" dictCode="bu_jygl_wslx"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('企业信息表')">导出</a-button>
      <a-button @click="downloadExcel" type="primary" style="margin-right: 10px"  icon="download">导入模板下载</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <a-popover title="自定义列" trigger="click" placement="leftBottom" :overlayStyle="{width:'50%'}" >
          <template slot="content" class="popoverWidth">
            <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
              <a-row>
                <template v-for="(item,index) in defColumns">
                  <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                    <a-col :span="8"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </template>
          <a class="floatRight"><a-icon type="setting" /> 自定义列</a>
        </a-popover>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text).split("/")[0] }}</div>
        </template>
        <template slot="pcaSlot1" slot-scope="text">
          <div>{{ getPcaText(text).split("/")[1] }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <bu-gsfwpt-qyxx-modal ref="modalForm" @ok="modalFormOk"></bu-gsfwpt-qyxx-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BuGsfwptQyxxModal from './modules/BuGsfwptQyxxModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import Area from '@/components/_util/Area'
  import Vue from "vue";

  export default {
    name: 'BuGsfwptQyxxList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BuGsfwptQyxxModal
    },
    data () {
      return {
        description: '企业信息表管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'业务类型',
            align:"center",
            dataIndex: 'wslx_dictText'
          },
          {
            title:'代征主体',
            align:"center",
            dataIndex: 'dzzt'
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'qymc'
          },
          {
            title:'法定代表人',
            align:"center",
            dataIndex: 'fddbr'
          },
          {
            title:'所属销售',
            align:"center",
            dataIndex: 'ssxs_dictText'
          },
          {
            title:'联系人',
            align:"center",
            dataIndex: 'lxr'
          },
          {
            title:'联系电话',
            align:"center",
            dataIndex: 'lxdh'
          },
          {
            title:'销售签约费率',
            align:"center",
            dataIndex: 'xsqyfl'
          },
          {
            title:'企业签约费率',
            align:"center",
            dataIndex: 'qyqyfl'
          },
          {
            title:'扣款方式',
            align:"center",
            dataIndex: 'kkfs_dictText'
          },
          {
            title:'开票电话',
            align:"center",
            dataIndex: 'kpdh'
          },

          {
            title:'所属省',
            align:"center",
            dataIndex: 'sss',
            scopedSlots: {customRender: 'pcaSlot'}
          },
          {
            title:'所属市',
            align:"center",
            dataIndex: 'ssss',
            scopedSlots: {customRender: 'pcaSlot1'}
          },
          {
            title:'开票地址',
            align:"center",
            dataIndex: 'kpdz'
          },
          {
            title:'开票类目',
            align:"center",
            dataIndex: 'kplm'
          },
          {
            title:'签约时间',
            align:"center",
            dataIndex: 'qysj',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同是否归档',
            align:"center",
            dataIndex: 'htsfgd_dictText'
          },
          {
            title:'合同是否到期',
            align:"center",
            dataIndex: 'htsfdq_dictText'
          },
          {
            title:'邮箱号',
            align:"center",
            dataIndex: 'yxh'
          },
          {
            title:'邮寄地址',
            align:"center",
            dataIndex: 'yjdz'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        //列设置
        settingColumns:[],
        //列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'业务类型',
            align:"center",
            dataIndex: 'wslx_dictText'
          },
          {
            title:'代征主体',
            align:"center",
            dataIndex: 'dzzt'
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'qymc'
          },
          {
            title:'法定代表人',
            align:"center",
            dataIndex: 'fddbr'
          },
          {
            title:'所属销售',
            align:"center",
            dataIndex: 'ssxs_dictText'
          },
          {
            title:'联系人',
            align:"center",
            dataIndex: 'lxr'
          },
          {
            title:'联系电话',
            align:"center",
            dataIndex: 'lxdh'
          },
          {
            title:'销售签约费率',
            align:"center",
            dataIndex: 'xsqyfl'
          },
          {
            title:'企业签约费率',
            align:"center",
            dataIndex: 'qyqyfl'
          },
          {
            title:'扣款方式',
            align:"center",
            dataIndex: 'kkfs_dictText'
          },
          {
            title:'开票电话',
            align:"center",
            dataIndex: 'kpdh'
          },
          {
            title:'所属省',
            align:"center",
            dataIndex: 'sss',
            scopedSlots: {customRender: 'pcaSlot'}
          },
          {
            title:'所属市',
            align:"center",
            dataIndex: 'ssss',
            scopedSlots: {customRender: 'pcaSlot1'}
          },
          {
            title:'开票地址',
            align:"center",
            dataIndex: 'kpdz'
          },
          {
            title:'开票类目',
            align:"center",
            dataIndex: 'kplm'
          },
          {
            title:'签约时间',
            align:"center",
            dataIndex: 'qysj',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同是否归档',
            align:"center",
            dataIndex: 'htsfgd_dictText'
          },
          {
            title:'合同是否到期',
            align:"center",
            dataIndex: 'htsfdq_dictText'
          },
          {
            title:'邮箱号',
            align:"center",
            dataIndex: 'yxh'
          },
          {
            title:'邮寄地址',
            align:"center",
            dataIndex: 'yjdz'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/qyxx/buGsfwptQyxx/list",
          delete: "/qyxx/buGsfwptQyxx/delete",
          deleteBatch: "/qyxx/buGsfwptQyxx/deleteBatch",
          exportXlsUrl: "/qyxx/buGsfwptQyxx/exportXls",
          importExcelUrl: "qyxx/buGsfwptQyxx/importExcel",

        },
        dictOptions:{},
        pcaData:'',
        superFieldList:[],
      }
    },
    created() {
      this.pcaData = new Area();
    this.getSuperFieldList();
      this.initColumns();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },
      initDictConfig(){
      },
      downloadExcel(){
        let url = process.env.BASE_URL +'企业信息导入模板.xls'
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', '企业信息基本信息.xls')
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      },
      getSuperFieldList(){
        let fieldList=[];

        fieldList.push({type:'string',value:'dzzt',text:'代征主体',dictCode:''})
        fieldList.push({type:'string',value:'qymc',text:'企业名称',dictCode:''})
        fieldList.push({type:'string',value:'fddbr',text:'法定代表人',dictCode:''})
        fieldList.push({type:'string',value:'ssxs',text:'所属销售',dictCode:'bu_gsfwpt_xsgl,name,id'})
        fieldList.push({type:'string',value:'lxr',text:'联系人',dictCode:''})
        fieldList.push({type:'string',value:'lxdh',text:'联系电话',dictCode:''})
        fieldList.push({type:'string',value:'xsqyfl',text:'销售签约费率',dictCode:''})
        fieldList.push({type:'string',value:'qyqyfl',text:'企业签约费率',dictCode:''})
        fieldList.push({type:'string',value:'kkfs',text:'扣款方式',dictCode:'kk_type'})
        fieldList.push({type:'string',value:'kpdh',text:'开票电话',dictCode:''})
        fieldList.push({type:'pca',value:'sss',text:'所属省'})
        fieldList.push({type:'pca',value:'ssss',text:'所属市'})
        fieldList.push({type:'string',value:'kpdz',text:'开票地址',dictCode:''})
        fieldList.push({type:'string',value:'kplm',text:'开票类目',dictCode:''})
        fieldList.push({type:'date',value:'qysj',text:'签约时间'})
        fieldList.push({type:'string',value:'htsfgd',text:'合同是否归档',dictCode:'ht_sfgd'})
        fieldList.push({type:'string',value:'htsfdq',text:'合同是否到期',dictCode:'ht_sfdq'})
        fieldList.push({type:'string',value:'yxh',text:'邮箱号',dictCode:''})
        fieldList.push({type:'string',value:'yjdz',text:'邮寄地址',dictCode:''})
        fieldList.push({type:'string',value:'wslx',text:'业务类型',dictCode:'bu_jygl_wslx'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  /*自定义列表*/
  .floatRight{
    float: right;
  }
  .ant-col-xl-6 {
    display: block;
    width: 13% !important;
  }
</style>